package com.basker.pisces.core.query.factory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.basker.pisces.core.enums.AggregateType;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString(callSuper = true)
public class AggregateQueryInfo extends AbstractQueryInfo {

    /**
     * 需要聚合的字段，为空默认查询所有主实体的属性
     */
    private Map<AggregateType, List<String>> aggregateFields = new LinkedHashMap<>();

    /**
     * 添加聚合字段
     *
     * @param type
     * @param selectFields
     */
    public void addAggregateFields(AggregateType type, String... aggregateFields) {
        List<String> fields = this.aggregateFields.get(type);
        if (fields == null) {
            fields = new ArrayList<>(4);
            this.aggregateFields.put(type, fields);
        }

        fields.addAll(Arrays.asList(aggregateFields));
    }

}
